<?php

namespace App\Models;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class MyDB
{
    /**
     * 开启日志
     */
    public static function enableLog()
    {
        DB::enableQueryLog();
    }

    /**
     * 记录sql
     */
    public static function sqlLog()
    {
        $queryLog = DB::getQueryLog();
        foreach ($queryLog as $queue) {
            $sqllog = str_replace_array('?', $queue['bindings'], $queue['query']);
            Log::info('[sql] ' . $sqllog);
        }
    }
}
